{% extends "admin/base.html" %}

{% if request.cookies.get('Scr1wCTFdLanguage') == 'en' %}
{% set en = true %}
{% else %}
{% set en = false %}
{% endif %}

{% block content %}
<div class="jumbotron">
    <div class="container">
        <h1><b>{{ "writeup Setting" if en else "题解上传设置" }}</b></h1>
    </div>
</div>
<div class="container">
    <div class="row">
        <div class="col-md-3">
            <ul class="nav nav-pills flex-column">
                <li class="nav-item">
                    <a class="nav-link active" data-toggle="pill"
                       href="#settings">{{ "Settings" if en else "插件设置" }}</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" data-toggle="pill" href="#record">{{ "Writeups" if en else "题解文件" }}</a>
                </li>
            </ul>
        </div>
        <div class="col-md-9">
            <div class="tab-content">
                <div class="config-section tab-pane fade show active" id="settings" role="tabpanel"
                     aria-autocomplete="none">
                    <form method="POST" accept-charset="utf-8" action="/admin/plugins/writeup"
                          class="form-horizontal">
                        {% set enabled = get_config('writeup:enabled') %}
                        <div class="form-group">
                            <label for="enabled">
                                {{ "Enable Switch" if en else "插件开关" }}
                                <small class="form-text text-muted">
                                    {{ "Whether to enable writeup upload" if en else "是否允许上传题解" }}
                                </small>
                            </label>
                            <select id="enabled" name="writeup:enabled" class="form-control custom-select">
                                <option value="true" {{
                                "selected" if enabled == true }}>{{ "ON" if en else "开启" }}</option>
                                <option value="false" {{
                                "selected" if enabled == false }}>{{ "OFF" if en else "关闭" }}</option>
                            </select>
                        </div>

                        {% set name = get_config('writeup:name') %}
                        <div class="form-group">
                            <label for="name">
                                {{ "writeup name format (Variable:user,team=>user.team)" if en else "题解文件命名格式 (可用变量:user,team=>user.team)" }}
                            </label>
                            <div class="input-group">
                                <input class="form-control" id='name' name='writeup:name'
                                       {% if name is defined and name !=None %}value="{{ name }}" {% endif %}>
                            </div>
                        </div>

                        <div class="submit-row float-right">
                            <button type="submit" tabindex="0" class="btn btn-md btn-primary btn-outlined">
                                {{ "Submit" if en else "确定" }}
                            </button>
                        </div>
                    </form>
                </div>
                <div class="tab-pane fade" id="record" role="tabpanel">
                    <table class="table">
                        <thead>
                        <tr>
                            <th class="text-center">{{ "File Name" if en else "文件名" }}</th>
                            <th class="text-center">{{ "Size" if en else "大小" }}</th>
                            <th class="text-center">{{ "Date" if en else "日期" }}</th>
                            <th class="text-center" colspan="2">{{ "Actions" if en else "操作" }}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {% for file in writeup_files %}
                        <tr>
                            <td>{{ file['name'] }}</td>
                            <td class="text-center">{{ file['size'] }}</td>
                            <td class="text-center">
                                <span data-time="{{ file['date'] | isoformat }}"></span>
                            </td>
                            <td class="text-center">
                                <a href="/plugins/writeup/admin/download?name={{file['name']}}" target="_blank" data-toggle="tooltip"
                                   data-placement="top">
                                    {{ "Download" if en else "下载" }}
                                    <i class="fas fa-file-download"></i>
                                </a>
                            </td>
                            <td class="text-center">
                                <a class="delete-writeup" data-filename="{{file['name']}}" href="javascript:void(0)" data-toggle="tooltip"
                                   data-placement="top">
                                    {{ "Delete" if en else "删除" }}
                                    <i class="fas fa-trash"></i>
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                        </tbody>
                    </table>

                    <div class="submit-row float-right">
                        <button type="button" tabindex="0" class="btn btn-md btn-primary btn-outlined download-all">
                            {{ "Download All" if en else "下载全部" }}
                        </button>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
{% endblock %}

{% block scripts %}
<script defer src="/plugins/writeup/static/config.js"></script>
<script defer src="/plugins/writeup/static/delete.js"></script>
{% endblock %}